<%@page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>
<script type="text/javascript" src="/components/editor/ckeditor.js"></script>
<script type="text/javascript" src="/dwr/engine.js"></script>
<script type="text/javascript" src="/dwr/util.js"></script>
<script type="text/javascript" src="/dwr/interface/DWRUserBiz.js"></script>
<script type="text/javascript">
	function initCKEditor() {
		//CKEDITOR.replace("editor");
	}
	function initSelectOptions() {
	    DWRUserBiz.queryAllCategoryList(function(list) {
			DWRUtil.removeAllOptions("categorys");
			DWRUtil.addOptions("categorys", list, "value", "text");

		    var aid = $("aid").value;
		    var categoryName = $("cname").value;
		    if (aid != null && aid.length > 0) {
				var opts = $("categorys").options;
				for (var i = 0; i < opts.length; i++) {
					if (opts[i].text == categoryName) {
						opts[i].selected = true;
					}
				}
		    }
	    });
	}
	function beforeSubmit() {
		if ($("aid").value.length == 0) {
			$("articleForm").action = "/saveArticle.do";
		} else {
			$("articleForm").action = "/updateArticle.do";
		}
		return true;
	}
</script>
<body>
	<form id="articleForm" name="articleForm" action="" method="POST" onsubmit="return beforeSubmit();">
		<input type="hidden" id="aid" name="aid" value="${article.id }"/>
		<input type="hidden" id="cname" name="cname" value="默认分类" />
		<p>标题：<input type="text" name="title" size="50" value="${article.title }" /></p>
		<p>
		    <textarea id="editor" name="content">${article.content.value }</textarea>
		    <script type="text/javascript">
		        CKEDITOR.replace("editor");
		    </script>
	    </p>
		<p>
		          分类：
		    <select id="categorys" name="categoryId"></select>
		    <script type="text/javascript">
		        initSelectOptions();
		    </script>
		</p>
		<input type="submit" value="Submit" />
	</form>
</body>